﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using WoBian.Controllers.Admin;
using WoBian.Lib.ConstString;
namespace WoBian
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(MapRouteControllers.AdminUserIndexView, MapRoutePath.AdminUserIndexView , new { controller = MapRouteControllers.AdminUser});
            routes.MapRoute(MapRouteControllers.AdminUserDetailView, MapRoutePath.AdminUserDetailView, new { controller = MapRouteControllers.AdminUser });
            routes.MapRoute(MapRouteControllers.AdminLogin, MapRoutePath.AdminLoginView, new { controller = MapRouteControllers.AdminLogin,action = "Login" });
            routes.MapRoute(MapRouteControllers.ValidateCode, MapRoutePath.ValidateCode, new { controller = MapRouteControllers.AdminLogin, action = "ValidateCode" });
            routes.MapRoute(MapRouteControllers.AdminIndex, MapRoutePath.AdminIndexView, new { controller = MapRouteControllers.AdminIndex, action = "Index" });
            routes.MapRoute(MapRouteControllers.AdminError, MapRoutePath.AdminErrorView, new { controller = MapRouteControllers.AdminError, action = "Error" });
            routes.MapRoute(MapRouteControllers.AdminSystemCodeIndexView, MapRoutePath.AdminSystemCodeIndexView, new { controller = MapRouteControllers.AdminSystemCode});
            routes.MapRoute(MapRouteControllers.AdminSystemCodeDetailView, MapRoutePath.AdminSystemCodeDetailView, new { controller = MapRouteControllers.AdminSystemCode });
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            SetViewEngines();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }

        protected static void SetViewEngines()
        {
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new MyViewEngines.WoBianViewEngine());
        }
    }
}